//
//  ViewController.m
//  06-UINavgationController
//
//  Created by 韩旭 on 16/7/21.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    设置navgationBar的属性
    self.view.backgroundColor = [UIColor whiteColor];
    //    UINavigationBar *navBar = [[UINavigationBar alloc] init];
    //    1.  标题title， 告诉用户, 我这个视图控制器干哈用的
    self.title = @"我是标题";
    //    2.
    self.navigationItem.title = @"你妹xxx";
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"张和为", @"S&B"]];
    seg.frame = CGRectMake(0, 0, 300, 20);
    seg.backgroundColor = [UIColor redColor];
    //    标题视图, 修改X,Y对视图本身位置没有影响
    self.navigationItem.titleView = seg;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(comBack:)];
    //    4. 左按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(addControl:)];
    //    5.
    //    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"XXX" style:UIBarButtonSystemItemReply target:self action:@selector(sdf)];
    
    //    6. rightBarButtonItems 数组
    //    barButtonItem数组中放1-2个为优
    //    7. 隐藏navgationBar YES 隐藏， NO 不隐藏 默认是NO
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBarHidden = NO;
    
    //   8 navgationBar背景样式默认为NO
    self.navigationController.navigationBar.barStyle = NO;
    //   9. 背景颜色 navgationBar的背景颜色
    self.navigationController.navigationBar.backgroundColor = [UIColor cyanColor];
    //    10. barTintColor Bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    //    11. tintColor Bar上 元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    //    12.transform  管理半透明的效果 ， YES为开启, NO为关闭
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    button.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
    //    设置为YES时, self.view坐标从原点开始
    //    设置为NO时, self.view坐标系从navgationBar下开始
    self.navigationController.navigationBar.translucent = YES;
    //    iOS7以后， 默认为yes
    //    13. 改变坐标效果, 与translucent为NO时效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
    //    页面跳转
}
- (void)addButton:(UIButton *)btn {
    //    页面跳转相关的有
    //    1 push  入栈 pushViewController
    //    2 pop   出栈 popToRootViewControllerAnimated
    //    将视图控制器入栈
    //    获取到navgationController例所有的控制器
    //    self.navigationController.viewControllers
    //    4.topViewController 栈顶视图控制器（最后入栈的）
    //    5. visibleViewController 可视控制器当前显示的,
    PushViewController *vc = [[PushViewController alloc] init];
    vc.view.backgroundColor = [UIColor redColor];
    vc.title = @"xiao";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)addControl:(UIBarButtonItem *)bar {
    NSLog(@"添加");
}
- (void)comBack:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回");
}
@end
